import Vue from 'vue';
import * as PhotoSwipeUtil from './photoswipe';
import * as PhotoSwipeDefaultUIUtil from './photoswipe-ui-default';
import VuePhotoswipe from './VuePhotoswipe';

let instance;

export const photoSwipeOpen = function (index, items, opts) {
    if (!instance) {
        const Vp = window.Vue ? window.Vue.extend(VuePhotoswipe) : Vue.extend(VuePhotoswipe);
        instance = new Vp({
            el: document.createElement('div'),
        });
        document.body.appendChild(instance.$el);
    }
    const pswpElement = document.querySelectorAll('.pswp')[0];
    const options = {
        fullscreenEl: false,
        shareEl: false,
        tapToClose: true,
        history: false,
        focus: false,
        showAnimationDuration: 10,
        hideAnimationDuration: 10,
        maxSpreadZoom: 5,
        index,
    };
    const obj = Object.assign(options, opts);

    const gallery = PhotoSwipeUtil.PhotoSwipe(pswpElement, PhotoSwipeDefaultUIUtil.PhotoSwipeUI_Default, items, obj);

    console.log(gallery);
    gallery.init();
}

// export default {
//     photoSwipeOpen,
// };

// if (typeof window !== 'undefined' && window.Vue) {
//     window.Vue.prototype.photoSwipeOpen = photoSwipeOpen;
// }
